package com.xmindguoguo.boot;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;

/**
 * 扫描规则 如果Application类所在的包为：io.github.gefangshuai.app，则只会扫描io.github.gefangshuai.app包及其所有子包
 * 如果service或dao所在包不在io.github.gefangshuai.app及其子包下，则不会被扫描 @ComponentScan注解进行指定要扫描的包以及要扫描的类。
 */
/*@EnableSwagger2Doc
//@SpringBootApplication(exclude = FreeMarkerAutoConfiguration.class)
@SpringBootApplication()
@EnableScheduling
@EnableAsync*/
@ServletComponentScan
//@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) // === same as @Configuration
// @EnableAutoConfiguration
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, FreeMarkerAutoConfiguration.class})
// @ComponentScan
//@EnableAdminServer // spring-boot-admin 监控
public class BootApplication {
    public static String server_port;
    public static String server_context_path;

    @Value("${server.port}")
    public void setServer_port(String server_port) {
        this.server_port = server_port;
    }

    @Value("${server.context-path}")
    public void setServer_context_path(String server_context_path) {
        this.server_context_path = server_context_path;
    }

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(BootApplication.class);
//        app.setBannerMode(Banner.Mode.OFF); // 1.5版本关闭 banner
        ApplicationContext ctx = app.run(args);
        System.err.println(BootApplication.class.getName() + ":启动成功");
        //追加启动之后打印需要访问的url
        System.err.println("项目启动路径=======http://localhost:" + server_port + server_context_path);

        // =================================================aop测试===============
        /*        ArithmeticCalculator arithmeticCalculator = (ArithmeticCalculator) ctx.getBean("arithmeticCalculator");
        System.out.println(arithmeticCalculator.getClass());
        int result = arithmeticCalculator.add(3, 5);
        System.out.println("result: " + result);
        
        result = arithmeticCalculator.div(5, 0);
        System.out.println("result: " + result);*/

        // ============================aop end ============================
        // 启动运行
//      SpringApplication.run(Application.class, args);
//获取一个指定的bean  
        // 允许额外的参数
        System.setProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow", "|{}");

//        Service service = ctx.getBean(Service.class);
        /**
         * 去掉banner
         */
//        SpringApplication app = new SpringApplication(Application.class);
////        app.setShowBanner(false); //1.3版本关闭 banner
//        app.setBannerMode(Banner.Mode.OFF);  // 1.5版本关闭 banner 
//        app.run(args);

        /**
         * 输出注入的指定的注解@Service
         */
//        ApplicationContext ctx = SpringApplication.run(Application.class, args);

//        String[] beanNames =  ctx.getBeanNamesForAnnotation(Configuration.class);
//        System.out.println("Configuration注解beanNames个数："+beanNames.length);
//        for(String bn:beanNames){
//            System.out.println(bn);
//        }

        /**
         * “ 获取所有的bean
         */
//        String[] beanNames =  ctx.getBeanDefinitionNames();
//        System.out.println("所以beanNames个数："+beanNames.length);
//        for(String bn:beanNames){
//            System.out.println(bn);
//        }
        /**
         * 热部署http://www.jb51.net/article/112473.htm
         */

    }

}